package org.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.core.BusEventService;
import org.example.core.RouteEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.bus.BusBridge;
import org.springframework.cloud.bus.BusProperties;
import org.springframework.cloud.bus.event.Destination;
import org.springframework.cloud.bus.event.PathDestinationFactory;
import org.springframework.cloud.bus.event.RefreshRemoteApplicationEvent;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/bus/publish")
public class GatewayRoutesApiController {
    @Resource
    private BusEventService busEventService;
    @Resource
    private BusProperties busProperties;
    @Resource
    private BusBridge busBridge;
    @Resource
    private PathDestinationFactory pathDestinationFactory;


    @GetMapping("/test")
    public Boolean testGateway(@RequestParam("routeNo") String routeNo){
        Destination destination = pathDestinationFactory.getDestination("cloud-bus");
        return busEventService.publishRouteEvent(routeNo);
//        RouteEvent event = new RouteEvent(
//                busProperties.getId(), "test", destination, routeNo
//        );
//        busBridge.send(event);
//        return true;
    }
}
